﻿package org.grizzly.web.interceptor;

import javax.servlet.ServletContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.common.ApplicationConstant;
import org.grizzly.entity.LoginInfo;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import flex.lms.entity.User;

public class UserSessionInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -2185920708747626659L;

	private static final Log logger = LogFactory
			.getLog(UserSessionInterceptor.class);

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {

		logger.info("Interceptor UserSessionInterceptor ... ");

		// 判断sesion是否失效
		User user = (User) ServletActionContext.getRequest().getSession()
				.getAttribute("loginUser");
		if (user == null) {
			logger.error("用户session失效！");
			return "sessionError";
		}

		return invocation.invoke();
	}

}
